package com.gimi.cloud.bbp.manage.consumer.service.prod.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.product.LogisticsCompanyDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.LogisticsCompanyFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.prod.LogisticsCompanyService;

@Service
public class LogisticsCompanyServiceImpl implements LogisticsCompanyService{
	
	@Autowired private LogisticsCompanyFeignService feignService;

	@Override
	public Response list(String requestData, HttpServletRequest request, HttpServletResponse response) {
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestData, LogisticsCompanyDTO.class);
		return feignService.list(dto);
	}

	@Override
	public Response info(String requestData, HttpServletRequest request, HttpServletResponse response) {
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestData, LogisticsCompanyDTO.class);
		if (dto.getLcId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		return feignService.info(dto);
	}

	@Override
	public Response addLogisticsCompany(String requestData, HttpServletRequest request, HttpServletResponse response) {
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestData, LogisticsCompanyDTO.class);
		if(null != dto.getLcId()){
			Response resp = new Response();
			resp.setResponseCode(ResponseCodeEnum.NO_DATA,"物流公司Id不为空，添加物流公司失败");
			return resp;
		}
		return feignService.saveOrUpdate(dto);
	}

	@Override
	public Response editLogisticsCompany(String requestData, HttpServletRequest request, HttpServletResponse response) {
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestData, LogisticsCompanyDTO.class);
		if(null == dto.getLcId()){
			Response resp = new Response();
			resp.setResponseCode(ResponseCodeEnum.NO_DATA,"物流公司Id为空，更新物流公司失败");
			return resp;
		}
		return feignService.saveOrUpdate(dto);
	}

	@Override
	public Response delete(String requestData, HttpServletRequest request, HttpServletResponse response) {
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestData, LogisticsCompanyDTO.class);
		if (dto.getLcId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		return feignService.delete(dto);
	}

}
